#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	
	int n;
	cin>>n;
	vector<int> a(n+1),v;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		v.push_back(i);
	}
	int nRet=0;
	do{
		bool flg=true;
		vector<int> vis(v.size()+1);
		for(int i=0;i<static_cast<int>(v.size());++i){
			if(vis[a[v[i]]]){
				flg=false;
				break;
			}
			vis[v[i]]=1;
		}
		if(flg){
			++nRet;
		}
	}while(next_permutation(v.begin(),v.end()));
	cout<<nRet<<endl;
	
	return 0;
}
